package com.zj.system.controller;

import com.seventh.common.pojo.R;
import com.zj.system.pojo.entity.Role;
import com.zj.system.pojo.entity.User;
import com.zj.system.pojo.vo.RoleVo;
import com.zj.system.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @program: clms-seventh
 * @description: 角色表的控制层
 * @author: 张静
 * @create: 2021-07-19 19:31
 **/
@RestController
@RequestMapping("system/role")

public class RoleController {
    @Autowired
    private RoleService roleService;
    @GetMapping("sel/{userId}")
    public R selRole(@PathVariable("userId") Integer userId){
        return roleService.selRole(userId);
    }
    @GetMapping("insRole/{userId}")
    public R insertRole(@PathVariable("userId") Integer userId,
                        @RequestParam List<Integer> userRole){
        return roleService.upUserRole(userId, userRole);
    }
    @PostMapping("sel/{currentPage}/{pageSize}")
    public R selR(@PathVariable("currentPage") Integer currentPage,
                  @PathVariable("pageSize") Integer pageSize,
                  @RequestBody RoleVo roleVo){
        return roleService.sel( pageSize,currentPage, roleVo);
    }
    @PutMapping("up/{roleId}/{status}")
    public R upStatus(@PathVariable("roleId") Integer roleId,
                      @PathVariable("status") Integer status){
        return roleService.upStatus(roleId,status);
    }
    @PutMapping("updateRoleById")
    public R update(@RequestBody Role role){
        return roleService.up(role);
    }
    @PostMapping("insertRole")
    public R insertUser(@RequestBody Role role){
        return roleService.ins(role);
    }
    @GetMapping("selById/{roleId}")
    public R selById(@PathVariable("roleId") Integer roleId){
        return roleService.selById(roleId);
    }
    @DeleteMapping("del/{roleId}")
    public R del(@PathVariable("roleId") Integer roleId){
        return roleService.del(roleId);
    }
    @PostMapping("selRoleName")
    public R selUserName(@RequestBody Role role){
        return roleService.selRoleName(role);
    }
}
